//
//  PostListHeaderView.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/10.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "PostListHeaderView.h"

@implementation PostListHeaderView

+ (CGFloat)calculateHeight {
    return kStatusBarHeight + NavBar_Height + 100 + 20+ 30;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.topHeight.constant = kStatusBarHeight + NavBar_Height;
    
    self.hotestBtn.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
    self.newestBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];

    [self.hotestBtn setTitleColor:UIColorHex(0x222222) forState:UIControlStateNormal];
    [self.newestBtn setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];
    
    self.hotSlide.hidden = NO;
    self.newestSlide.hidden = YES;
    
}

- (IBAction)backAction:(id)sender {
    if (self.PostListHeaderViewBlock) {
        self.PostListHeaderViewBlock(PostListHeaderViewActionType_back);
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.segView pp_clipCorners:UIRectCornerTopLeft|UIRectCornerTopRight radius:16];
}


- (void)fillWithModel:(CommunityThemeModel *)model {
    
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.themeUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:model.themeUrl] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        UIImage *resultImage = [image blurImageWithRadius:20];
        [self.bgImageView setImage:resultImage];
    }];

    self.mainTitleLab.text = model.themeTitle;
    self.subTitleLab.text = model.themeSynopsis;
    
}

- (IBAction)hotAction:(id)sender {
    
    self.hotestBtn.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
    self.newestBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];

    [self.hotestBtn setTitleColor:UIColorHex(0x222222) forState:UIControlStateNormal];
    [self.newestBtn setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];

    
    self.hotSlide.hidden = NO;
    self.newestSlide.hidden = YES;
    
    if (self.PostListHeaderViewBlock) {
        self.PostListHeaderViewBlock(PostListHeaderViewActionType_hot);
    }
}

- (IBAction)newAction:(id)sender {
    
    self.hotSlide.hidden = YES;
    self.newestSlide.hidden = NO;
    

    [self.newestBtn setTitleColor:UIColorHex(0x222222) forState:UIControlStateNormal];
    [self.hotestBtn setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];

    self.newestBtn.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
    self.hotestBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
    
    if (self.PostListHeaderViewBlock) {
        self.PostListHeaderViewBlock(PostListHeaderViewActionType_new);
    }
}

@end
